// pages/mine/balance/index.js

const other = require('../../../service/other')

Page({

    /**
     * 页面的初始数据
     */
    data: {
        param: {
            customerId: '',
            queryRequest: {
                pageNum: 1,
                pageSize: 10
            },
        },
        balanceList: [],
        balanceInfo: {
            totalMoney: 0,
            shenHeZhong: 0,
            yiTiXian: 0,
            keTiXian: 0,
            weiDaoZhang:0,
        }
    },
    onLoad() {

    },
    onShow() {
        this.initData()
    },
    initData() {
        this.setData({
            ['param.customerId']: wx.getStorageSync("userInfo").id,

            balanceList: []

        })
        let param = this.data.param
        other.getOverallBalance(param, (res) => {
            if (res.code != '00000') {
                wx.showToast({
                    title: '网络错误了!',
                    icon: 'none'
                })
                return
            }
            const data = res.data
            let totalMoney = (data.keTiXian / 100) + (data.yiTiXian / 100) + (data.shenHeZhong / 100)
            this.setData({
                ['balanceInfo.totalMoney']: totalMoney,
                ['balanceInfo.shenHeZhong']: data.shenHeZhong / 100,
                ['balanceInfo.yiTiXian']: data.yiTiXian / 100,
                ['balanceInfo.keTiXian']: data.keTiXian / 100,
                ['balanceInfo.weiDaoZhang']: data.weiDaoZhang / 100
            })
            let keyValue = {
                0: '返利',
                1: '分销',
                2: '商盟分销'
            }
            let customerKeyValue = {
                0: '下级客户',
                1: '我的客户'
            }
            let tempList = data.liuShui.records || []

            tempList.forEach(item => {
                item.typeText = keyValue[item.moldType]
                item.price = item.price / 100
                item.fatherText = customerKeyValue[item.father]
            })
            let balanceList = this.data.balanceList
            //console.log(1111, balanceList, tempList)
            balanceList = balanceList.concat(tempList)
            //console.log(balanceList)
            balanceList.forEach(item => {
                if (item.status == "0") {
                    item.statusText = "已到账"
                } else if (item.status == "1") {
                    item.statusText = "未到账"
                } else {
                    item.statusText = "退款"
                }
            })
            this.setData({
                balanceList: balanceList
            })
        })
    },
    dealMoney() {
        let keTiXian = this.data.balanceInfo.keTiXian
        if (keTiXian <= 0) {
            wx.showToast({
                title: '当前可提现收益为0,快去赚取收益吧!',
                icon: 'none'
            })
            return
        }
        wx.navigateTo({
            url: '/pages/mine/balance/deal/index',
        })
    },
    goToDetial() {

    }
})